#include "StdAfx.h"
#include "CircuitLine.h"


CCircuitLine::CCircuitLine(void)
{
	m_dblStartPosX = 0.0;	
	m_dblStartPosY = 0.0;	
	m_dblEndPosX = 0.0;	
	m_dblEndPosY = 0.0;	
	m_dblBorderWidth = 0.0;	
	m_linePattern = SOLID_LINE;
	m_dblColor[0] = 0.0;
	m_dblColor[1] = 0.0;
	m_dblColor[2] = 0.0;
	m_bSelected = false;	

	m_eStartLineShape = LINE_SHAPE_NONE; 
	m_eEndLineShape = LINE_SHAPE_NONE; 
    m_dblLineShapeSize = 0.0; 
}

CCircuitLine::CCircuitLine(const CCircuitLine *pEntityObj)
	: CCircuitUnit(pEntityObj)
{
	m_dblStartPosX = pEntityObj->GetStartPosX();	
	m_dblStartPosY = pEntityObj->GetStartPosY();
	m_dblEndPosX = pEntityObj->GetEndPosX();
	m_dblEndPosY = pEntityObj->GetEndPosY();
	m_dblBorderWidth = pEntityObj->GetBorderWidth();
	m_linePattern = pEntityObj->GetLinePattern();
	m_dblColor[0] = pEntityObj->GetColorR();
	m_dblColor[1] = pEntityObj->GetColorG();
	m_dblColor[2] = pEntityObj->GetColorB();
	m_bSelected = pEntityObj->IsSelect();
	m_eStartLineShape = pEntityObj->GetStartLineShape(); 
	m_eEndLineShape = pEntityObj->GetEndLineShape(); 
	m_dblLineShapeSize = pEntityObj->GetLineShapeSize(); 
}

CCircuitLine::CCircuitLine(CICircuit *pParentEnt)
	: CCircuitUnit(pParentEnt)
{
	m_dblStartPosX = 0.0;	
	m_dblStartPosY = 0.0;	
	m_dblEndPosX = 0.0;	
	m_dblEndPosY = 0.0;	
	m_dblBorderWidth = 0.0;	
	m_linePattern = SOLID_LINE;
	m_dblColor[0] = 0.0;
	m_dblColor[1] = 0.0;
	m_dblColor[2] = 0.0;
	m_bSelected = false;
	m_eStartLineShape = LINE_SHAPE_NONE; 
	m_eEndLineShape = LINE_SHAPE_NONE; 
	m_dblLineShapeSize = 0.0; 
}

CCircuitLine::~CCircuitLine(void)
{
	Clear();
}

void CCircuitLine::Serialize(CArchive & ar)
{
	if (ar.IsStoring())
	{
		ar << m_dblStartPosX;	
		ar << m_dblStartPosY;	
		ar << m_dblEndPosX;	
		ar << m_dblEndPosY;	
		ar << m_dblBorderWidth;	
		ar << m_linePattern;
		ar << m_dblColor[0];
		ar << m_dblColor[1];
		ar << m_dblColor[2];
		ar << m_bSelected;	
		ar << m_eStartLineShape;
		ar << m_eEndLineShape;
		ar << m_dblLineShapeSize;
	}
	else
	{
		ar >> m_dblStartPosX;	
		ar >> m_dblStartPosY;	
		ar >> m_dblEndPosX;	
		ar >> m_dblEndPosY;	
		ar >> m_dblBorderWidth;	
		int nLinePatt(0);
		ar >> nLinePatt;
		m_linePattern = (eLinePattern)nLinePatt;
		ar >> m_dblColor[0];
		ar >> m_dblColor[1];
		ar >> m_dblColor[2];
		ar >> m_bSelected;	
		if( CObj::m_lFileVersion >= 70 )
		{

			ar >>nLinePatt;
			m_eStartLineShape = (eLineShape)nLinePatt;
			ar >>nLinePatt;
			m_eEndLineShape = (eLineShape)nLinePatt;
			ar >>m_dblLineShapeSize;
		}
	}
	CCircuitUnit::Serialize(ar);
}

CObj *CCircuitLine::Clone() const
{
	return new CCircuitLine(this);
}

void CCircuitLine::Transform(const CMatrix transf)
{

}

bool CCircuitLine::GetBox(double & dblLeft, double & dblBottom, double & dblRight, double & dblTop) const
{
	return false;
}

void CCircuitLine::Clear()
{

}

void CCircuitLine::CopyDisplayObj(long lSourceLayerId, long lDestLayerId)
{
	CEntityObj::CopyDisplayObj(lSourceLayerId, lDestLayerId);
}

void CCircuitLine::DeleteDisplayObj(long lLayerId)
{
	CEntityObj::DeleteDisplayObj(lLayerId);
}

CDisplayObj *CCircuitLine::CreateDisplayObj(long lLayerId)
{
	CCircuitLineDisObj *pLineDis = new CCircuitLineDisObj(this);
	pLineDis->SetLayerId(lLayerId);
	return pLineDis;
}

void CCircuitLine::CalcBox()
{
	m_minX = min(m_dblStartPosX, m_dblEndPosX);
	m_minY = min(m_dblStartPosY, m_dblEndPosY);
	m_maxX = max(m_dblStartPosX, m_dblEndPosX);
	m_maxY = max(m_dblStartPosY, m_dblEndPosY);
}

eCircuitUnitEntType CCircuitLine::GetUnitType() const
{
	return CIRCUIT_LINE;
}

double CCircuitLine::GetStartPosX() const
{
	return m_dblStartPosX;
}
double CCircuitLine::GetStartPosY() const
{
	return m_dblStartPosY;
}

double CCircuitLine::GetEndPosX() const
{
	return m_dblEndPosX;
}

double CCircuitLine::GetEndPosY() const
{
	return m_dblEndPosY;
}

double CCircuitLine::GetBorderWidth() const
{
	return m_dblBorderWidth;
}

eLinePattern CCircuitLine::GetLinePattern() const
{
	return m_linePattern;
}

double CCircuitLine::GetColorR() const
{
	return m_dblColor[0];
}

double CCircuitLine::GetColorG() const
{
	return m_dblColor[1];
}

double CCircuitLine::GetColorB() const
{
	return m_dblColor[2];
}

bool CCircuitLine::IsSelect() const
{
	return m_bSelected;
}

void CCircuitLine::SetStartPosX(double posX)
{
	m_dblStartPosX = posX;
}

void CCircuitLine::SetStartPosY(double posY)
{
	m_dblStartPosY = posY;
}

void CCircuitLine::SetEndPosX(double posX)
{
	m_dblEndPosX = posX;
}

void CCircuitLine::SetEndPosY(double posY)
{
	m_dblEndPosY = posY;
}

void CCircuitLine::SetBorderWidth(double dblWidth)
{
	m_dblBorderWidth = dblWidth;
}

void CCircuitLine::SetLinePattern(eLinePattern pattern)
{
	m_linePattern = pattern;
}

void CCircuitLine::SetColorR(double colR)
{
	m_dblColor[0] = colR;
}

void CCircuitLine::SetColorG(double colG)
{
	m_dblColor[1] = colG;
}

void CCircuitLine::SetColorB(double colB)
{
	m_dblColor[2] = colB;
}

void CCircuitLine::SetSelect(bool bFlag)
{
	m_bSelected = bFlag;
}